home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / performCreateSet.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  11.0 KB  |  435 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. // Creation Date:  March 19, 1997
  22. //
  23. //  Description:
  24. //         An option window used to create a named set, and (if desired) add
  25. //         it to a partition.
  26. //
  27.  
  28. //
  29. //  Procedure Name:
  30. //      setOptionVars
  31. //
  32. //  Description:
  33. //        Initialize the option values.
  34. //
  35. //  Input Arguments:
  36. //        Whether to set the options to default values.
  37. //
  38. //  Return Value:
  39. //      None.
  40. //
  41. proc setOptionVars(int $forceFactorySettings)
  42. {
  43.     // The variables in this "option" box are not options because
  44.     // bug reports (84564) indicated that users did not want the options
  45.     // to carry over from session to session.
  46.     //
  47. }
  48.  
  49. //
  50. //  Procedure Name:
  51. //      createSetSetup
  52. //
  53. //  Description:
  54. //        Update the state of the option box UI to reflect the option values.
  55. //
  56. //  Input Arguments:
  57. //      parent               - Top level parent layout of the option box UI.
  58. //                             Required so that UI object names can be 
  59. //                             successfully resolved.
  60. //
  61. //    forceFactorySettings - Whether the option values should be set to
  62. //                             default values.
  63. //
  64. //  Return Value:
  65. //      None.
  66. //
  67. global proc createSetSetup(string $parent, int $forceFactorySettings)
  68. {
  69.     // Retrieve the option settings
  70.     //
  71.     setOptionVars( $forceFactorySettings );
  72.     
  73.     setParent $parent;
  74.  
  75.     checkBoxGrp -edit -value1 0 partitionWidget;
  76.     checkBoxGrp -edit -value2 0 partitionWidget;
  77.     optionMenuGrp -e -enable 0 partitionListWidget;
  78.     
  79.     textFieldGrp -e -text "set1" setNameWidget;
  80. }
  81.  
  82. //
  83. //  Procedure Name:
  84. //      createSetCallback
  85. //
  86. //  Description:
  87. //        Update the option values with the current state of the option box UI.
  88. //
  89. //  Input Arguments:
  90. //      parent - Top level parent layout of the option box UI.  Required so
  91. //               that UI object names can be successfully resolved.
  92. //
  93. //    doIt   - Whether the command should execute.
  94. //
  95. //  Return Value:
  96. //      None.
  97. //
  98. global proc createSetCallback(string $parent, int $doIt)
  99. {
  100.     setParent $parent;
  101.  
  102.     if ($doIt) {
  103.         performCreateSet 0; 
  104.         addToRecentCommandQueue "performCreateSet 0" "Create Set";
  105.     }
  106. }
  107.  
  108. //
  109. //  Procedure Name:
  110. //      createSetOptions
  111. //
  112. //  Description:
  113. //        Construct the option box UI.  Involves accessing the standard option
  114. //        box and customizing the UI accordingly.
  115. //
  116. //  Input Arguments:
  117. //      None.
  118. //
  119. //  Return Value:
  120. //      None.
  121. //
  122. proc createSetOptions()
  123. {
  124.     //    Name of the command for this option box.
  125.     //
  126.     string $commandName = "createSet";
  127.  
  128.     //    Build the option box actions.
  129.     //
  130.     string $callback = ($commandName + "Callback");
  131.     string $setup = ($commandName + "Setup");
  132.  
  133.     //    STEP 1:  Get the option box.
  134.     //    ============================
  135.     //
  136.     //    The value returned is the name of the layout to be used as
  137.     //    the parent for the option box UI.
  138.     //
  139.     string $layout = getOptionBox();
  140.     setParent $layout;
  141.     
  142.     //    STEP 2:  Pass the command name to the option box.
  143.     //    =================================================
  144.     //
  145.     //    Any default option box behaviour based on the command name is set 
  146.     //    up with this call.  For example, updating the 'Help' menu item with
  147.     //    the name of the command.
  148.     //
  149.     setOptionBoxCommandName("sets");
  150.     
  151.     //    STEP 3:  Activate the default UI template.
  152.     //    ==========================================
  153.     //
  154.     //    Activate the default UI template so that the layout of this 
  155.     //    option box is consistent with the layout of the rest of the 
  156.     //    application.
  157.     //
  158.     setUITemplate -pushTemplate DefaultTemplate;
  159.  
  160.     //    STEP 4: Create option box contents.
  161.     //    ===================================
  162.     //    
  163.     //    This, of course, will vary from option box to option box.    
  164.     
  165.     //    Turn on the wait cursor.
  166.     //
  167.     waitCursor -state 1;
  168.  
  169.     tabLayout -tabsVisible 0 -scrollable 1;
  170.     
  171.     string $parent = `columnLayout -adjustableColumn 1`;
  172.     
  173.     // name for the set
  174.     //
  175.     formLayout nameLayout;
  176.         textFieldGrp
  177.             -label "Name"
  178.             setNameWidget;
  179.     setParent ..;
  180.  
  181.     separator;
  182.  
  183.     // whether or not the set should be added to partition(s)
  184.     checkBoxGrp
  185.         -label "Add to a Partition:"
  186.         -label1 "Only If Exclusive"
  187.         -label2 "By Making Exclusive"
  188.         -numberOfCheckBoxes 2
  189.          -on1 "optionMenuGrp -e -enable 1 partitionListWidget; checkBoxGrp -e -value2 0 partitionWidget;"
  190.          -on2 "optionMenuGrp -e -enable 1 partitionListWidget; checkBoxGrp -e -value1 0 partitionWidget;"        
  191.          -offCommand "optionMenuGrp -e -enable 0 partitionListWidget"
  192.         partitionWidget;
  193.  
  194.     // Create an option menu listing the partitions
  195.     //
  196.     optionMenuGrp -l "Partition" partitionListWidget;
  197.  
  198.     // add all the partitions to the menu
  199.     //
  200.     int $pp;
  201.     string $partitionArray[];
  202.     $partitionArray = `ls -type partition`;
  203.     int $partitionCount = size($partitionArray);
  204.     for ($pp = 0; $pp < $partitionCount; $pp++)
  205.     {
  206.         // Do not list the render or character partitions as 
  207.                 // adding items to them is only going to cause confusion.
  208.         //
  209.         if ( ($partitionArray[$pp] != "renderPartition") &&
  210.              ($partitionArray[$pp] != "characterPartition") )     
  211.         {
  212.             menuItem -l $partitionArray[$pp];
  213.         }
  214.     }
  215.     setParent $parent;
  216.  
  217.     separator;
  218.  
  219.     optionMenuGrp -e -enable false partitionListWidget;
  220.  
  221.     //    Turn off the wait cursor.
  222.     //
  223.     waitCursor -state 0;
  224.     
  225.     //    Step 5: Deactivate the default UI template.
  226.     //    ===========================================
  227.     //
  228.     setUITemplate -popTemplate;
  229.  
  230.     //    Step 6: Customize the buttons.  
  231.     //    ==============================
  232.     //
  233.     //    Provide more descriptive labels for the buttons.  This is not 
  234.     //    necessary, but in some cases, for example, a button labelled 
  235.     //    'Create' may be more meaningful to the user than one labelled
  236.     //    'Apply'.
  237.     //
  238.     //    Disable those buttons that are not applicable to the option box.
  239.     //
  240.     //    Attach actions to those buttons that are applicable to the option
  241.     //    box.  Note that the 'Close' button has a default action attached 
  242.     //    to it that will hide the window.  If a a custom action is
  243.     //    attached to the 'Close' button then be sure to call the 'hide the
  244.     //    option box' procedure within the custom action so that the option
  245.     //    box is hidden properly.
  246.  
  247.     //    'Apply' button.
  248.     //
  249.     string $applyBtn = getOptionBoxApplyBtn();
  250.     button -edit
  251.         -command ($callback + " " + $parent + " " + 1)
  252.         $applyBtn;
  253.  
  254.     //    'Save' button.
  255.     //
  256.     string $saveBtn = getOptionBoxSaveBtn();
  257.     button -edit 
  258.         -command ($callback + " " + $parent + " " + 0 + "; hideOptionBox")
  259.         $saveBtn;
  260.  
  261.     //    'Reset' button.
  262.     //
  263.     string $resetBtn = getOptionBoxResetBtn();
  264.     button -edit 
  265.         -command ($setup + " " + $parent + " " + 1)
  266.         $resetBtn;
  267.  
  268.     //    Step 7: Set the option box title.
  269.     //    =================================
  270.     //
  271.     setOptionBoxTitle("Create Set Options");
  272.  
  273.     //    Step 8: Customize the 'Help' menu item text.
  274.     //    ============================================
  275.     //
  276.     setOptionBoxHelpTag( "CreateSet" );
  277.  
  278.     //    Step 9: Set the current values of the option box.
  279.     //    =================================================
  280.     //
  281.     eval (($setup + " " + $parent + " " + 0));    
  282.     
  283.     //    Step 10: Show the option box.
  284.     //    =============================
  285.     //
  286.     showOptionBox();
  287. }
  288.  
  289. //
  290. //  Procedure Name:
  291. //      createSetHelp
  292. //
  293. //  Description:
  294. //        Return a short description about this command.
  295. //
  296. //  Input Arguments:
  297. //      None.
  298. //
  299. //  Return Value:
  300. //      string.
  301. //
  302. proc string createSetHelp()
  303. {
  304.  
  305.     return 
  306.     "  Command: sets - Creates a new set.\n" +
  307.     "Selection: Selected items are placed in the set.";
  308. }
  309.  
  310. //
  311. //  Procedure Name:
  312. //      assembleCmd
  313. //
  314. //  Description:
  315. //        Construct the command that will apply the option box values.
  316. //
  317. //  Input Arguments:
  318. //      None.
  319. //
  320. proc string assembleCmd()
  321. {
  322.     string $cmd = "optionBoxExample1";
  323.  
  324.     setOptionVars(false);
  325.     
  326.     // get the partition name
  327.     string $setName = "set1";
  328.     if (`textFieldGrp -exists setNameWidget`) {
  329.         $setName = `textFieldGrp -q -text setNameWidget`;
  330.     }
  331.  
  332.     int $addState = 0;
  333.     if (`checkBoxGrp -exists partitionWidget`) {
  334.         if (`checkBoxGrp -q -value1 partitionWidget`) {
  335.             $addState = 1;  // try to add
  336.         } else if (`checkBoxGrp -q -value2 partitionWidget`) {
  337.             $addState = 2;  // force add
  338.         }
  339.     }
  340.  
  341.     string $partitionName = "";
  342.     if (`optionMenuGrp -exists partitionListWidget`) {
  343.         $partitionName = `optionMenuGrp -q -v partitionListWidget`;
  344.     }
  345.  
  346.     // create the sets command string
  347.     if (size($setName)) {
  348.         $cmd = "$createSetResult = `sets -name "+$setName;
  349.     } else {
  350.         $cmd = "$createSetResult = `sets";
  351.     }
  352.  
  353.     // if we are going to forcibly add the items to a partition
  354.     // then make an empty set first. Later we'll force the items
  355.     // into our set.
  356.     //
  357.     if ($addState == 2) {
  358.         $cmd += " -em";
  359.     }
  360.  
  361.     $cmd += "`;";
  362.  
  363.     //
  364.     // put the set into the partition
  365.     //
  366.     if ($addState != 0) {
  367.         $cmd += " partition -e -addSet " + $partitionName+" $createSetResult;";
  368.     }
  369.  
  370.     //
  371.     // If the addState is "force to add", force the selected items
  372.     // into the set. This will remove the items from the other set(s)
  373.     // in the partition if necessary since the set has already been
  374.     // added to the partition.
  375.     //
  376.     if ($addState == 2) {
  377.         $cmd += " sets -edit -forceElement $createSetResult;";
  378.     }
  379.     
  380.     return $cmd;
  381. }
  382.  
  383. //
  384. //  Procedure Name:
  385. //      performCreateSet
  386. //
  387. //  Description:
  388. //        Perform the create set command using the corresponding 
  389. //        option values.  This procedure will also show the option box
  390. //        window if necessary as well as construct the command string
  391. //        that will invoke the optionBoxExample1 command with the current
  392. //        option box values.
  393. //
  394. //  Input Arguments:
  395. //      0 - Execute the command.
  396. //      1 - Show the option box dialog.
  397. //      2 - Return the command.
  398. //
  399. global proc string performCreateSet(int $action)
  400. {
  401.     string $cmd = "";
  402.  
  403.     switch ($action) {
  404.  
  405.         //    Execute the command.
  406.         //
  407.         case 0:
  408.             //    Get the command.
  409.             //
  410.             $cmd = `assembleCmd`;
  411.  
  412.             //    Execute the command with the option settings.
  413.             //
  414.             evalEcho($cmd);
  415.  
  416.             break;
  417.  
  418.         //    Show the option box.
  419.         //
  420.         case 1:
  421.             createSetOptions;
  422.             break;
  423.  
  424.         //    Return the command string.
  425.         //
  426.         case 2:
  427.             //    Get the command.
  428.             //
  429.             $cmd = `assembleCmd`;
  430.             break;
  431.     }
  432.     return $cmd;
  433. }
  434.  
  435.